package messageboard;
import java.sql.*;

public class saveword {
  String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  String sConnStr = "jdbc:odbc:forStudy";
  Connection conn = null;

  public saveword() {
   try {
     Class.forName(sDBDriver);
   }catch(java.lang.ClassNotFoundException e) {
     System.out.println(e.getMessage());
   }
  }

  public boolean executeUpdate(String sql) {
    boolean success = false;
    try {
      conn = DriverManager.getConnection(sConnStr,"","");
      Statement stmt = conn.createStatement();
      stmt.executeUpdate(sql);
      success=true;
    }catch(SQLException e) {
      success=false;
    }
    return success;
  }
  
   public ResultSet executeQuery(String sql) {
    ResultSet rs = null;
    try {
      conn = DriverManager.getConnection(sConnStr,"","");
      Statement stmt = conn.createStatement();
      rs = stmt.executeQuery(sql);
    }catch(SQLException e) {
      System.err.println(e.getMessage());
    }
    return rs;
  }

  public void close(){
    try{
     if(!conn.isClosed())
       conn.close();
    }catch(SQLException el){
       el.printStackTrace(); 
    }
 } 
}